package com.eco.fanliapp.job.jdOrderJob;

import com.eco.fanliapp.common.OrderTaskUtils;
import com.eco.fanliapp.service.IJdOrderInfoService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.Serializable;
@DisallowConcurrentExecution
@PersistJobDataAfterExecution
public class jdOrderDetail implements Job, Serializable {

    private static final Logger log = LoggerFactory.getLogger(jdOrderDetail.class);

    @Autowired
    private IJdOrderInfoService jdOrderInfoService;

    @Autowired
    private OrderTaskUtils orderTaskUtils;


    public jdOrderDetail() {}

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {

        //取得job详情
        JobDetail jobDetail = context.getJobDetail();
        JobDataMap dataMap =  jobDetail.getJobDataMap();

        int executeCount = 0;
        if (dataMap.containsKey("runCount")) {
            executeCount = dataMap.getInt("runCount");
        }

        // 增量计数并将其存储回 JobDataMap，这样可以适当保持工作状态
        executeCount++;
        dataMap.put("runCount", executeCount);
        long beginTime = System.currentTimeMillis();
        log.info("***************************************开始执行定时任务-拉取jd付款订单定时任务-OrderPayTaskNew：executeCount=" + executeCount + "--beginTime=" + beginTime);

        jdOrderInfoService.handleOrder();

        log.info("***************************************结束执行定时任务-拉取jd付款订单定时任务");

    }


}

